#include <ximera/logger.hpp>
#include <fstream>

namespace ximera
{
    Logger log(L"ximera.log");

    Logger::Logger(String const& fileName)
        : _strm(0), _ownStream(false)
    {
        this->fileName(fileName);
    }

    Logger::Logger(std::wostream* strm, bool ownStream)
        : _strm(0), _ownStream(false)
    {
        this->stream(strm, ownStream);
    }

    Logger::~Logger()
    {
        clear();
    }

    void Logger::fileName(String const& fileName)
    {
        stream(new std::wofstream(fileName.c_str()), true);
    }

    void Logger::stream(std::wostream* strm, bool ownStream)
    {
        clear();

        _strm = strm;
        _ownStream = ownStream;
    }

    void Logger::clear()
    {
        if (_ownStream)
            delete _strm;

        _strm = 0;
        _ownStream = false;
    }
}
